package com.imau.servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/hello")
public class HelloServlet implements Servlet {



    private ServletConfig config;

    //初始化: 资源加载 执行1次
    public void init(ServletConfig servletConfig) throws ServletException {

        this.config= servletConfig;
        System.out.println("init....");
    }

    public ServletConfig getServletConfig() {
        System.out.println("getServletConfig....");
        return this.config;
    }

    //服务 处理请求 每一次 访问执行
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {

        System.out.println("service....");
        String user = this.config.getInitParameter("user");
        String password = this.config.getInitParameter("password");

        System.out.println(user+"====="+password);
        //集合
        Enumeration<String> initParameterNames = this.config.getInitParameterNames();
        while (initParameterNames.hasMoreElements())
        {
            String parmeterName = initParameterNames.nextElement();
            System.out.println(parmeterName+"=====>"+this.config.getInitParameter(parmeterName));
        }
        System.out.println("ServletContext==="+config.getServletContext());


    }

    public String getServletInfo() {
        System.out.println("getServletInfo....");

        return config.getServletName();
    }

    //销毁 资源 1次
    public void destroy() {
        System.out.println("destroy....");
    }
}
